package com.lashou.chunshen.lashoutuangou.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.lashou.chunshen.lashoutuangou.MainActivity;
import com.lashou.chunshen.lashoutuangou.R;
import com.lashou.chunshen.lashoutuangou.core.BaseFragment;

import butterknife.InjectView;
import butterknife.OnClick;
import pl.droidsonroids.gif.GifImageView;

/**
 * Created by Administrator on 2016/8/31.
 */

public class LoadingFragment extends BaseFragment {

    @InjectView(R.id.image)
    GifImageView image;
    @InjectView(R.id.guide_close)
    ImageView close;


    private static final String TAG = LoadingFragment.class.getSimpleName();
    private String paramInt;
    private String defaultparamInt = "0";

    public static LoadingFragment newInstance(int paramInt) {
        LoadingFragment newFragment = new LoadingFragment();
        Bundle bundle = new Bundle();
        bundle.putString("paramInt", paramInt + "");
        newFragment.setArguments(bundle);
        return newFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        paramInt = args != null ? args.getString("paramInt") : defaultparamInt;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        onCreateFragmentView();
    }

    @Override
    public int getContentViewId() {
        return R.layout.fragment_loading01;
    }


    public void onCreateFragmentView() {
        switch (paramInt) {
            case "0":
                //替換資源文件
                image.setImageResource(R.drawable.guide_first);
                break;
            case "1":
                image.setImageResource(R.drawable.guide_second);
                break;
            case "2":
                image.setImageResource(R.drawable.guide_third);
                break;
        }
    }



    @OnClick(R.id.image)
    public void image(GifImageView gifImageView) {
        if (paramInt.equals("2")) {
            //START
            Intent intent = new Intent(getActivity(), MainActivity.class); // 从启动动画ui跳转到主ui
            startActivity(intent);
            if (getActivity() != null) {
                getActivity().finish();
            }
        }
    }

    @OnClick(R.id.guide_close)
    public void close(ImageView close) {
        //START
        Intent intent = new Intent(getActivity(), MainActivity.class); // 从启动动画ui跳转到主ui
        startActivity(intent);
        if (getActivity() != null) {
            getActivity().finish();
        }
    }
}
